<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="isemirmalzeme" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{isemirmalzemeHome.managed ? 'Edit' : 'Add'} Isemirmalzeme</f:facet>

             <s:decorate id="extendedDataTableField" template="layout/edit.xhtml">
                <ui:define name="label">Malzeme</ui:define>
                	<h:panelGrid columns="3">
						<h:panelGroup>
							<h:graphicImage id="link" value="/img/selection.png" styleClass="hidelink"/>
              					<rich:componentControl for="popup" attachTo="link" operation="show" event="onclick"/>
					    </h:panelGroup>
			     		<h:outputLabel value="   " /> 
	                	<h:outputLabel value="#{isemirmalzemeHome.instance.malzeme==null ? 'Malzeme Seç' : isemirmalzemeHome.instance.malzeme.kod}   #{isemirmalzemeHome.instance.malzeme==null ? ' ' : isemirmalzemeHome.instance.malzeme.ad}" />
	                </h:panelGrid>
            </s:decorate>

            <s:decorate id="makskullanimmiktariField" template="layout/edit.xhtml">
                <ui:define name="label">Max.Kul.Miktari</ui:define>
                <h:inputText id="makskullanimmiktari"
                       required="true"
                          value="#{isemirmalzemeHome.instance.makskullanimmiktari}">
                    <a:support event="onblur" reRender="makskullanimmiktariField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>



            <s:decorate id="miktarField" template="layout/edit.xhtml">
                <ui:define name="label">Bir Üründeki Miktar</ui:define>
                <h:inputText id="miktar"
                          value="#{isemirmalzemeHome.instance.miktar}">
                    <a:support event="onblur" reRender="miktarField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{isemirmalzemeHome.persist}"
                       disabled="#{!isemirmalzemeHome.wired}"
                       rendered="#{!isemirmalzemeHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{isemirmalzemeHome.update}"
                       rendered="#{isemirmalzemeHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{isemirmalzemeHome.remove}"
                      immediate="true"
                       rendered="#{isemirmalzemeHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/Isemirmalzeme.xhtml"
                rendered="#{isemirmalzemeHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty isemirmalzemeFrom ? 'IsemirmalzemeList' : isemirmalzemeFrom}.xhtml"
                rendered="#{!isemirmalzemeHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Isemir *" labelClass="required">
    <div class="association" id="isemirParent">

        <h:outputText value="There is no isemir associated with this isemirmalzeme."
                   rendered="#{isemirmalzemeHome.instance.isemir == null}"/>

        <rich:dataTable var="_isemir"
                   value="#{isemirmalzemeHome.instance.isemir}"
                rendered="#{isemirmalzemeHome.instance.isemir != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="isemirTable">
        <h:column>
            <f:facet name="header">Id</f:facet>
            <h:outputText value="#{_isemir.id}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Isemirno</f:facet>
            <h:outputText value="#{_isemir.isemirno}"/>
        </h:column>
        <h:column rendered="#{authenticator.isAdmin()}">
            <f:facet name="header">Firma id</f:facet>
            <h:outputText value="#{_isemir.firma.ad}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Isemirtarihi</f:facet>
            <h:outputText value="#{_isemir.isemirtarihi}">
                <s:convertDateTime type="date" dateStyle="short"/>
            </h:outputText>
        </h:column>
        <h:column>
            <f:facet name="header">Isletme id</f:facet>
            <h:outputText value="#{_isemir.isletme.ad}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Siparisno</f:facet>
            <h:outputText value="#{_isemir.siparisno}"/>
        </h:column>        
        <h:column>
            <f:facet name="header">Urun id</f:facet>
            <h:outputText value="#{_isemir.urun.urunno} - #{_isemir.urun.adi} ( #{_isemir.urun.kalip.kod} #{_isemir.urun.ambalaj})"/>
        </h:column>        
        <h:column>
            <f:facet name="header">Musteri id</f:facet>
            <h:outputText value="#{_isemir.musteri.ad}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Planlananadet</f:facet>
            <h:outputText value="#{_isemir.planlananadet}"/>
        </h:column>
        <h:column>
            <f:facet name="header">Termintarihi</f:facet>
            <h:outputText value="#{_isemir.termintarihi}">
                <s:convertDateTime type="date" dateStyle="short"/>
            </h:outputText>
        </h:column>
        <h:column>
            <f:facet name="header">Ulke id</f:facet>
            <h:outputText value="#{_isemir.ulke.ad}"/>
        </h:column>

        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{isemirmalzemeHome.instance.isemir != null ? 'changeParent' : 'selectParent'}" value="#{isemirmalzemeHome.instance.isemir != null ? 'Change' : 'Select'} isemir"
                       view="/IsemirList.xhtml">
                <f:param name="from" value="IsemirmalzemeEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>

    <rich:tab label="Isemirharekets" rendered="#{authenticator.isAdmin()}">
        <h:form styleClass="association" id="isemirhareketsChildren">

            <h:outputText value="There are no isemirharekets associated with this isemirmalzeme."
                       rendered="#{empty isemirmalzemeHome.isemirharekets}"/>

            <rich:dataTable value="#{isemirmalzemeHome.isemirharekets}"
                           var="_isemirhareket"
                      rendered="#{not empty isemirmalzemeHome.isemirharekets}"
                    rowClasses="rvgRowOne,rvgRowTwo"
                            id="isemirhareketsTable">
                <rich:column sortBy="#{_isemirhareket.id}">
                    <f:facet name="header">Id</f:facet>
                    <h:outputText value="#{_isemirhareket.id}"/>
                </rich:column>
                <rich:column sortBy="#{_isemirhareket.miktar}">
                    <f:facet name="header">Miktar</f:facet>
                    <h:outputText value="#{_isemirhareket.miktar}"/>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{isemirmalzemeHome.managed}" id="isemirharekets">
        <div class="actionButtons">
            <s:button id="addisemirhareket"
                   value="Add isemirhareket"
                    view="/IsemirhareketEdit.xhtml"
             propagation="none">
                 <f:param name="isemirmalzemeId"
                         value="#{isemirmalzemeHome.instance.id}"/>
                 <f:param name="isemirhareketFrom" value="Isemirmalzeme"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>
    
</rich:tabPanel>

	 <rich:modalPanel id="popup" width="540" height="520" resizeable="false" onmaskclick="#{rich:component('popup')}.hide()">
        <f:facet name="header">
            <h:panelGroup>
                <h:outputText value="Malzeme Seçimi"></h:outputText>
            </h:panelGroup>
        </f:facet>
        <f:facet name="controls">
            <h:panelGroup>
                <h:graphicImage value="/img/close.png" styleClass="hidelink" id="hidelink"/>
                <rich:componentControl for="popup" attachTo="hidelink" operation="hide" event="onclick"/>
            </h:panelGroup>
        </f:facet>
		
        <h:panelGrid id="seciliUrunBilgisi">
	        <s:decorate id="kalipekiField" template="layout/edit.xhtml">
	            <ui:define name="label">Seçili Malzeme</ui:define>
	            <h:outputLabel value="#{isemirmalzemeHome.instance.malzeme.kod} - #{isemirmalzemeHome.instance.malzeme.ad}"/>
	        </s:decorate>
        </h:panelGrid>        
       
        <a:form reRender="seciliUrunBilgisi">
	        <h:panelGrid>
		        	<rich:extendedDataTable rows="10" value="#{isemirmalzemeHome.urunsDataModel}" var="urun" id="table" width="500px" height="350px"
		        		sortMode="#{isemirmalzemeHome.sortMode}" selectionMode="#{isemirmalzemeHome.selectionMode}" 
		        		tableState="#{isemirmalzemeHome.tableState}" selection="#{isemirmalzemeHome.selection}">
		        	   	<a:support event="onselectionchange" reRender="seciliUrunBilgisi,extendedDataTableField" action="#{isemirmalzemeHome.takeSelection()}"/>
		               	<rich:column sortable="true" sortBy="#{urun.kod}" id="col_2" 
		               		filterBy="#{urun.kod}" filterEvent="onkeyup" width="170px" label="Malzeme Kodu">
		                   	<f:facet name="header">
		                    	<h:outputText value="Malzeme Kodu" id="state_name"/>
		                   	</f:facet>
		                   	<h:outputText value="#{urun.kod}" id="cap_state"/>
		               	</rich:column>
		               	<rich:column sortable="true" sortBy="#{urun.ad}" id="col_3" 
		               		filterBy="#{urun.ad}" filterEvent="onkeyup" width="330px" label="Malzeme Adı">
		                   	<f:facet name="header">
		                    	<h:outputText value="Malzeme Adı" id="state_capital"/>
		                   	</f:facet>
		                   	<h:outputText value="#{urun.ad}" id="cap_name"/>
		               	</rich:column>		               	
		           	</rich:extendedDataTable>
	           <rich:datascroller for="table" maxPages="5"/>
	        </h:panelGrid>
	        
	        <h:panelGrid columns="2" style="margin-left: 37%;" >
	        	<a:commandButton value="Tamam" style=" width : 60px;" action="#{isemirmalzemeHome.takeSelection()}" reRender="seciliUrunBilgisi,extendedDataTableField,save,update" onclick="#{rich:component('popup')}.hide()"/>
	        	<a:commandButton value="İptal" style=" width : 60px;" action="#{isemirmalzemeHome.clearSelectedUrun()}" reRender="seciliUrunBilgisi,extendedDataTableField,save,update" onclick="#{rich:component('popup')}.hide()" />
	        </h:panelGrid>
		</a:form>
    </rich:modalPanel>

</ui:define>

</ui:composition>
